package com.arrogames.blondbattle.ui 
{
	import com.arrogames.blondbattle.assets.AssetManager;
	import com.arrogames.blondbattle.GameModel;
	import com.arrogames.blondbattle.model.WorldDefinition;
	import com.arrogames.blondbattle.ui.buttons.MusicButton;
	import com.arrogames.blondbattle.ui.buttons.WorldButton;
	import feathers.controls.LayoutGroup;
	import feathers.controls.Screen;
	import feathers.layout.TiledRowsLayout;
	import starling.core.RenderSupport;
	import starling.display.Image;
	import starling.events.Event;
	import starling.textures.Texture;
	
	/**
	 * ...
	 * @author Robin van den Bogaard
	 */
	public class MenuScreen extends Screen {
		
		public var model:GameModel; //injected by ScreenNavigator
		
		private var container:LayoutGroup;
		
		private var musicButton:MusicButton = null;
		
		public function MenuScreen() {
			this.width = 800;
			this.height = 450;
			addEventListener(Event.ADDED_TO_STAGE, addedToStage);
		}
		
		private function addedToStage(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
			
			var bg:Image = new Image(AssetManager.instance.getTexture("MenuBackground"));
			this.addChild(bg);
			
			container = new LayoutGroup();
			container.x = 0;
			container.y = 250;
			container.width = 800;
			container.height = 200;
			
			for each (var world:WorldDefinition in model.availableWorlds.data) {
				var btn:WorldButton = new WorldButton(world.name, world);
				container.addChild(btn);
			}
			
			var btnLayout:TiledRowsLayout = new TiledRowsLayout();
			btnLayout.horizontalAlign = TiledRowsLayout.HORIZONTAL_ALIGN_CENTER;
			btnLayout.verticalAlign = TiledRowsLayout.VERTICAL_ALIGN_TOP;
			btnLayout.paddingTop = 10;
			btnLayout.paddingRight = 15;
			btnLayout.paddingBottom = 10;
			btnLayout.paddingLeft = 15;
			btnLayout.gap = 5;
			btnLayout.useSquareTiles = false;
			container.layout = btnLayout;
			
			this.addChild(container);
			
			musicButton = new MusicButton(model.isMuted());
			musicButton.x = 10;
			musicButton.y = 10;
			addChild(musicButton);
		}
	}

}